﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Deck deck1;
        Deck deck2;
        Random rand = new Random();

        public Form1()
        {
            InitializeComponent();

            ResetDeck(1);
            ResetDeck(2);
        }

        private void RedrawDeck(int DeckNumber)
        {
            if (DeckNumber == 1)
            {
                listDeck1.Items.Clear();
                foreach (string cardName in deck1.GetCardNames())
                    listDeck1.Items.Add(cardName);
                lblDeck1.Text = "Deck #1 (" + deck1.Count + " cards)";
            }
            else
            {
                listDeck2.Items.Clear();
                foreach (string cardName in deck2.GetCardNames())
                    listDeck2.Items.Add(cardName);
                lblDeck2.Text = "Deck #2 (" + deck2.Count + " cards)";
            }

        }

        private void btnMoveToDeck2_Click(object sender, EventArgs e)
        {
            if (listDeck1.SelectedIndex >= 0)
            deck2.Add(deck1.Deal(listDeck1.SelectedIndex));
            RedrawDeck(1);
            RedrawDeck(2);
        }

        private void btnShuffleDeck1_Click(object sender, EventArgs e)
        {
            deck1.Shuffle();
            RedrawDeck(1);
        }

        private void btnReset1_Click(object sender, EventArgs e)
        {
            ResetDeck(1);
        }

        private void btnShuffleDeck2_Click(object sender, EventArgs e)
        {
            deck2.Shuffle();
            RedrawDeck(2);
        }

        private void btnReset2_Click(object sender, EventArgs e)
        {
            ResetDeck(2);
        }

        private void btnMoveToDeck1_Click(object sender, EventArgs e)
        {
            if(listDeck2.SelectedIndex >= 0)
            deck1.Add(deck2.Deal(listDeck2.SelectedIndex));
            RedrawDeck(1);
            RedrawDeck(2);
        }

        public void ResetDeck(int deckToReset)
        {
            if (deckToReset == 1)
            {
                Card[] cards = new Card[rand.Next(1, 10)];

                for (int i = 0; i < cards.Length; i++)
                {
                    cards[i] = new Card((Card.Suits)rand.Next(0, 4), (Card.Values)rand.Next(1,14));
                }

                deck1 = new Deck(cards);
                deck1.Sort();
                RedrawDeck(1);
            }
            if (deckToReset == 2)
            {
                deck2 = new Deck();
                RedrawDeck(2);
            }
        }


    }
}